package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Stocked;
import com.ruoyi.system.service.IStockedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓储管理Controller
 * 
 * @author 张旭
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/system/stocked")
public class StockedController extends BaseController
{
    @Autowired
    private IStockedService stockedService;

    /**
     * 查询仓储管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:stocked:list')")
    @GetMapping("/list")
    public TableDataInfo list(Stocked stocked)
    {
        startPage();
        List<Stocked> list = stockedService.selectStockedList(stocked);
        return getDataTable(list);
    }

    /**
     * 导出仓储管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:stocked:export')")
    @Log(title = "仓储管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Stocked stocked)
    {
        List<Stocked> list = stockedService.selectStockedList(stocked);
        ExcelUtil<Stocked> util = new ExcelUtil<Stocked>(Stocked.class);
        util.exportExcel(response, list, "仓储管理数据");
    }

    /**
     * 获取仓储管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:stocked:query')")
    @GetMapping(value = "/{stockedId}")
    public AjaxResult getInfo(@PathVariable("stockedId") Long stockedId)
    {
        return success(stockedService.selectStockedByStockedId(stockedId));
    }

    /**
     * 新增仓储管理
     */
    @PreAuthorize("@ss.hasPermi('system:stocked:add')")
    @Log(title = "仓储管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Stocked stocked)
    {
        return toAjax(stockedService.insertStocked(stocked));
    }

    /**
     * 修改仓储管理
     */
    @PreAuthorize("@ss.hasPermi('system:stocked:edit')")
    @Log(title = "仓储管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Stocked stocked)
    {
        return toAjax(stockedService.updateStocked(stocked));
    }

    /**
     * 删除仓储管理
     */
    @PreAuthorize("@ss.hasPermi('system:stocked:remove')")
    @Log(title = "仓储管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockedIds}")
    public AjaxResult remove(@PathVariable Long[] stockedIds)
    {
        return toAjax(stockedService.deleteStockedByStockedIds(stockedIds));
    }
}
